package com.cetccst.securitysuite;

import android.app.Application;
import android.util.Log;

import com.cetccst.securitysuite.hostsdk.SSApiEventHandler;
import com.cetccst.securitysuite.kv.SSKV;
import com.cetccst.securitysuite.log.SSLogger;
import com.cetccst.securitysuite.mqtt.SSMqtt;
import com.cetccst.securitysuite.network.LoginHttpRequester;
import com.cetccst.securitysuite.network.UserHttpRequester;

import cn.com.cetccst.activation.ActivationManager;
import cn.com.cetccst.appshield.AppShieldManager;
import cn.com.cetccst.appstore.AppStoreManager;
import cn.com.cetccst.basiccollection.BasicInfoEngine;
import cn.com.cetccst.basiccollection.MockDeviceInfoOwner;
import cn.com.cetccst.compliancecheck.ComplianceCheckManager;
import cn.com.cetccst.datacenter.collection.CollectionRepository;
import cn.com.cetccst.datacenter.message.InboxMessageRespository;
import cn.com.cetccst.dataupload.DataUploadManager;
import cn.com.cetccst.deviceoperation.DeviceOperator;
import cn.com.cetccst.devicerestriction.DeviceRestrictionManager;
import cn.com.cetccst.hostsdk.HostSdkManager;
import cn.com.cetccst.location.LocationService;
import cn.com.cetccst.distribution.DistributionManager;
import cn.com.cetccst.mdm.MdmDeviceAdminReceiver;
import cn.com.cetccst.mdm.engine.BaseMDMEngine;
import cn.com.cetccst.mdm.MDMManager;
import cn.com.cetccst.messagecenter.MessageManager;
import cn.com.cetccst.tools.ToolsManager;
import cn.com.cetccst.usercenter.UserCenterManager;

public class SecurityApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        //TODO 以下初始化会根据业务流程放置，这里偷懒了
        //日志管理组件
        SSLogger.initialize(this);
        //KV组件
        SSKV.initialize(this);
        //Tools工具中日志的初始化
        ToolsManager.setLogger(SSLogger.logger);
        ToolsManager.setKVStore(SSKV.kvStore);
        ToolsManager.initialize(this);//不调用这个也没关系
        //数据中心
        CollectionRepository.initialize(this);
        InboxMessageRespository.initialize(this);
        //接入SDK
        HostSdkManager.initialize(this, new SSApiEventHandler(this));
        HostSdkManager.setLogger(SSLogger.logger); //可选，可以使用同一个日志记录，否则HostSdk将使用HostSdk的日志
        //mqtt
        SSMqtt.initialize(this, "tcp://172.18.28.100:1883");
        //network
        UserHttpRequester.initialize(this);
        LoginHttpRequester.initialize(this);
        //激活模块
        ActivationManager.initialize(this);

        LocationService.setKVStore(SSKV.kvStore);
        LocationService.setLogger(SSLogger.logger);
        LocationService.getInstance().initialize(this);
        BasicInfoEngine.initialize(this);
        MessageManager.initialize(this);

        //应用商店
        AppStoreManager.setLogger(SSLogger.logger);
        AppStoreManager.setKVStore(SSKV.kvStore);
        AppStoreManager.initialize(this);

        //用户中心
        UserCenterManager.setLogger(SSLogger.logger);
        UserCenterManager.setKVStore(SSKV.kvStore);

        //分发
        DistributionManager.initialize(this, "tcp://172.18.28.100:1883");
        MDMManager.initMockEngine(this, MdmDeviceAdminReceiver.getComponentName(this),
                getPackageName() + ".provider", new BaseMDMEngine.Callback() {
                    @Override
                    public void log(String msg) {
                        Log.e("mdm_engine", msg);
                    }
                });
        //合规性（认证完成之后才初始化，前提条件申请phonestate和定位权限）
        ComplianceCheckManager.initialize(this);

        //设备功能锁，也就是设备管控
        DeviceRestrictionManager.initialize(this);

        //设备操作
        DeviceOperator.initialize(this);

        //数据上报
        DataUploadManager.initialize(this);

        //应用护盾
        AppShieldManager.initialize(this);
    }
}
